package org.iff.infra.spring.webapp;

import javax.servlet.ServletContextEvent;

import org.iff.infra.domain.InstanceFactory;
import org.iff.infra.spring.factory.SpringInstanceProvider;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class DayatangContextLoaderListener extends ContextLoaderListener {

	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		if (InstanceFactory.getInstanceProvider() == null) {
			WebApplicationContext applicationContext = WebApplicationContextUtils
					.getRequiredWebApplicationContext(event.getServletContext());
			SpringInstanceProvider springProvider = new SpringInstanceProvider(
					applicationContext);
			InstanceFactory.setInstanceProvider(springProvider);
		}
	}

}
